<?php
include("config.php");
include("include/db_connect.php");
include("include/session.php");
include("include/common.php");

if(isset($_SESSION['user_id'])) {
	$userInfo = getUserInfo($_SESSION['user_id']);
	
	get_page("index", array("name" => $userInfo[0]));

} else if(isset($_REQUEST['email']) && isset($_REQUEST['password'])) {
	$result = login($_REQUEST['email'], $_REQUEST['password']);
	
	if($result == 0) {
		$_SESSION['user_id'] = getUserId($_REQUEST['email']);
		$userInfo = getUserInfo($_SESSION['user_id']);
		get_page("index", array("name" => $userInfo[0]));
	} else {
		get_page("index_login", array("error" => "Error: Invalid Information!"));
	}

} else {
	get_page("index_login");
}
?>
